package controller;

import view.UI;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class JaoFenTimer {
    private Timer timer;
    private int remainingTime;
    private Controller controller;
    private int currentTimer; // 记录当前倒计时阶段，0表示中间阶段，1表示东部阶段，2表示西部阶段
    public  String decision;
    public String eastDecision;
    public String westDecison;
    public PlayCardsTimer playCardsTimer;
    public JaoFenTimer(int delay, Controller controller) {
        this.controller = controller;
        remainingTime = delay;
        currentTimer = 0;

        ActionListener actionListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                decision = UI.enterGameJFrame.enterGameJPanel.soreJLabel.getText();
                eastDecision = UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.getText();
                westDecison = UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.getText();

                if (currentTimer == 0) { // 中间阶段
                    UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(true);
                    UI.enterGameJFrame.enterGameJPanel.jTextField.setText("倒计时：" + String.valueOf(remainingTime));
                    UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                    UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);


                    //当时间为0的时候
                    if (remainingTime == 0) {
                        UI.enterGameJFrame.enterGameJPanel.soreJLabel.setText("不叫分");
                        UI.enterGameJFrame.enterGameJPanel.jaoFen1Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen2Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen3Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.noJaoButton.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(false);


                    } else if (decision.equals("不叫分") || decision.equals("叫1分") || decision.equals("叫2分")) {
                        currentTimer++;
                        UI.enterGameJFrame.enterGameJPanel.jaoFen1Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen2Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen3Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.noJaoButton.setVisible(false);

                                //  remainingTime = delay;
                           /* } else if (decision.equals("叫3分")) {
                                JOptionPane.showMessageDialog(null,"恭喜王五成为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jaoFen1Button.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jaoFen2Button.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jaoFen3Button.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.noJaoButton.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
                                timer.stop();*/

                    } else if (decision.equals("叫3分")) {
                        JOptionPane.showMessageDialog(null,"恭喜屑狐狸成为地主");
                        UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen1Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen2Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jaoFen3Button.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.noJaoButton.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                        UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                        UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
//                        UI.enterGameJFrame.enterGameJPanel.cardLis();
                        timer.stop();
                        playCardsTimer = new PlayCardsTimer(20,controller);



                    }

                } else if (currentTimer == 1) { // 东部阶段
                    remainingTime = delay;
                    UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(true);
                    UI.enterGameJFrame.enterGameJPanel.eastTextField.setText("倒计时：" + String.valueOf(remainingTime));
                    UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                    UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                    if (decision.equals("不叫分")) {//上家不叫分
                        // 上家不加分，下家随机叫1、2、3分
                        Random random = new Random();
                        int randomPoints = random.nextInt(3); // 生成1到3的随机整数
                        switch (randomPoints) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫1分");
                                currentTimer++;
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫2分");
                                currentTimer++;
                                break;
                            case 2:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 4:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("不叫分");
                                currentTimer++;
                                break;
                        }
                    } else if (decision.equals("叫1分")) {
                        // 上家叫1分，下家可以选择不叫、叫2分或叫3分
                        Random random = new Random();
                        int randomChoice = random.nextInt(2); // 生成0到2的随机整数
                        switch (randomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("不叫分");
                                currentTimer++;
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫2分");
                                currentTimer++;
                                break;
                            case 2:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                        }
                    } else if (decision.equals("叫2分")) {
                        // 上家叫2分，下家可以选择不叫、叫3分
                        Random random = new Random();
                        int randomChoice = random.nextInt(2); // 生成0到2的随机整数

                        switch (randomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("不叫分");
                                currentTimer++;
                                break;

                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;

                        }
                    }
                } else if (currentTimer == 2) { // 西部阶段
                    remainingTime = delay;
                    UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(true);
                    UI.enterGameJFrame.enterGameJPanel.westTextField.setText("倒计时：" + String.valueOf(remainingTime));
                    UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                    UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                    if (eastDecision.equals("不叫分") && decision.equals("不叫分")) {
                        // 上家不加分，下家随机叫1、2、3分
                        Random random = new Random();
                        int westRandomPoints = random.nextInt(3); // 生成1到3的随机整数

                        switch (westRandomPoints) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫1分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                               playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫2分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                               playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 2:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 4:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                                timer.stop();
                                break;
                        }
                    } else if (eastDecision.equals("不叫分") && decision.equals("叫1分")) {
                        // 上家叫1分，下家可以选择不叫、叫2分或叫3分
                        Random random = new Random();
                        int westRandomChoice = random.nextInt(2); // 生成0到2的随机整数
                        switch (westRandomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫2分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                               playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 2:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                                JOptionPane.showMessageDialog(null,"恭喜屑狐狸为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;

                        }
                    } else if (eastDecision.equals("叫1分") && decision.equals("不叫分")) {
                        Random random = new Random();
                        int westRandomChoice = random.nextInt(2); // 生成0到2的随机整数
                        switch (westRandomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫2分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 2:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不加分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                               playCardsTimer = new PlayCardsTimer(20,controller);
                                currentTimer++;
                        }


                    } else if (decision.equals("叫1分") && eastDecision.equals("叫2分")) {
                        // 上家叫2分，下家可以选择不叫、叫3分
                        Random random = new Random();
                        int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                        switch (westRandomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                               playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);

                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                        }

                    } else if (decision.equals("不叫分") && eastDecision.equals("叫2分")) {
                        Random random = new Random();
                        int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                        switch (westRandomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                                JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                        }
                    } else if (decision.equals("叫2分") && eastDecision.equals("不叫分")) {
                        Random random = new Random();
                        int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                        switch (westRandomChoice) {
                            case 0:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                                JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                            case 1:
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                                JOptionPane.showMessageDialog(null,"恭喜屑狐狸为地主");
                                UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
                                timer.stop();
                                playCardsTimer = new PlayCardsTimer(20,controller);
                                break;
                        }
                    }
                } else if (eastDecision.equals("不叫分") && decision.equals("叫1分")) {
                    // 上家叫1分，下家可以选择不叫、叫2分或叫3分
                    Random random = new Random();
                    int westRandomChoice = random.nextInt(2); // 生成0到2的随机整数
                    switch (westRandomChoice) {
                        case 0:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫2分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 1:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                           playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 2:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                            JOptionPane.showMessageDialog(null,"恭喜屑狐狸为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
                            timer.stop();
                           playCardsTimer = new PlayCardsTimer(20,controller);
                            break;

                    }
                } else if (eastDecision.equals("叫1分") && decision.equals("不叫分")) {
                    Random random = new Random();
                    int westRandomChoice = random.nextInt(2); // 生成0到2的随机整数
                    switch (westRandomChoice) {
                        case 0:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫2分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 1:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                           playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 2:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不加分");
                            JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            currentTimer++;
                    }


                } else if (decision.equals("叫1分") && eastDecision.equals("叫2分")) {
                    // 上家叫2分，下家可以选择不叫、叫3分
                    Random random = new Random();
                    int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                    switch (westRandomChoice) {
                        case 0:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 1:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                            JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);

                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                    }

                } else if (decision.equals("不叫分") && eastDecision.equals("叫2分")) {
                    Random random = new Random();
                    int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                    switch (westRandomChoice) {
                        case 0:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                           playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 1:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                            JOptionPane.showMessageDialog(null,"恭喜堂主为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(true);
                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                    }
                } else if (decision.equals("叫2分") && eastDecision.equals("不叫分")) {
                    Random random = new Random();
                    int westRandomChoice = random.nextInt(1); // 生成0到2的随机整数

                    switch (westRandomChoice) {
                        case 0:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("叫3分");
                            JOptionPane.showMessageDialog(null,"恭喜椰羊为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(true);
                            timer.stop();
                           playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                        case 1:
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setText("不叫分");
                            JOptionPane.showMessageDialog(null,"恭喜屑狐狸为地主");
                            UI.enterGameJFrame.enterGameJPanel.soreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.eastSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.westSoreJLabel.setVisible(false);
                            UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setText("地主");
                            UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(true);
                            timer.stop();
                            playCardsTimer = new PlayCardsTimer(20,controller);
                            break;
                    }


                if (remainingTime < 0) {
                        UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                    }
                }

                remainingTime--;

                if (remainingTime == -1) {
                    remainingTime = delay;
                    currentTimer++;

                    if (currentTimer == 3) { // 所有阶段倒计时结束，停止计时器
                        timer.stop();
                        UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                    }
                }


            }


        };


        timer = new Timer(1000, actionListener);
        start();
    }

    public void start() {
        timer.start();
    }

    public void stop() {

        timer.stop();

    }
}